package dk.netl.dashboard.widgets.alivewidget;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.layout.Stack;

/**
 * @author G41324
 */
public class AliveRow extends HBox {

    public var serverInfo: ServerInfo;

    public var isAlive: Boolean;

    def serverUp: ImageView = ImageView {
                image: Image {
                    url: "{__DIR__}button_green_add.gif"
                     }
                preserveRatio: true
                translateX: -5
                scaleX: 1.2
                scaleY: 1.2
                opacity: 0
            }
    def serverDown: ImageView = ImageView {
                image: Image {
                    url: "{__DIR__}button_red_delete.gif"
                     }
                preserveRatio: true
                translateX: -5
                scaleX: 1.2
                scaleY: 1.2
                opacity: 0
            }

    // skal kaldes hvert minut
    public function updateState(): Void {
        if (serverInfo.isAlive()) {
            serverUp.opacity = 1;
            serverDown.opacity = 0;
            this.isAlive = true;
        } else {
            serverUp.opacity = 0;
            serverDown.opacity = 1;
            this.isAlive = false;
        }
    }

    init {
        translateY = 10 + 100 * serverInfo.getIndex();
        translateX = 30;

        content = [Stack {
                        content: [
                            serverUp,
                            serverDown,
                        ]
                    },
                    Text {
                        content: serverInfo.getName()
                        font: Font.font("Verdana", 75)
                        fill: Color.WHITE
                    }
                ]
    }

}
